<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Axios POST Request Example</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('myForm').addEventListener('submit', function(event){
                event.preventDefault(); // 阻止表单默认提交行为
                sendPostRequest();
            });
        });

        function sendPostRequest() {
            var name = document.getElementById('name').value;
            var phone = document.getElementById('phone').value;

            var data = {
                name: name,
                phone: phone
            };

            axios.post('http://192.168.2.45:8008/user/register/', data,{
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            })
                .then(function (response) {
                    console.log('Response:', response.data);
                    document.getElementById('response').innerText = 'Response: ' + JSON.stringify(response.data);
                })
                .catch(function (error) {
                    console.error('Request failed:', error);
                    document.getElementById('response').innerText = 'Request failed: ' + error.message;
                });
        }
    </script>
</head>
<body>

<h2>Axios POST Request Example</h2>

<form id="myForm">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name"><br><br>

    <label for="phone">Phone:</label>
    <input type="text" id="phone" name="phone"><br><br>

    <input type="submit" value="Submit">
</form>

<div id="response"></div>

</body>
</html>
